<!--
 * @Descripttion:
 * @version: 1.0.0
 * @Author: htang
 * @Date: 2023-11-09 10:21:36
 * @LastEditors: htang
 * @LastEditTime: 2024-03-08 16:46:42
-->
<template>
  <div class="left-echarts-node">
    <div class="tip">
      <span>今日统计</span>
      <dv-decoration2 :dur="2" />
    </div>
    <div class="card flex items-center justify-between">
      <div class="title">设备数量</div>
      <CountTo :startVal="0" :endVal="onlineEquipmentCount" class="value" />
    </div>
    <div class="card flex items-center justify-between" style="background-color: rgb(146, 72, 128)">
      <div class="title">今日报警</div>
      <CountTo :startVal="0" :endVal="alarmTotal" class="value" />
    </div>
  </div>
</template>

<script>
import { ref, watch, getCurrentInstance, onMounted, defineComponent, onUnmounted, nextTick } from 'vue';
import { Progress } from 'ant-design-vue';
import { equipmentCountApi } from '/@/api/equipment/index';
import { alarmCountApi } from '/@/api/alarm/index';
import { CountTo } from '/@/components/CountTo/index';
import '@/assets/js/highcharts/highcharts.js';
import '@/assets/js/highcharts/highcharts-3d.js';
import '@/assets/js/highcharts/modules/exporting.js';
export default defineComponent({
  components: { Progress, CountTo },
  setup() {
    let { proxy } = getCurrentInstance();

    let options = ref({});

    let chart;

    // 今日报警总数
    let alarmTotal = ref(0);

    // 在线设备总数
    let onlineEquipmentCount = ref(0);

    function alarmCount() {
      alarmCountApi().then((res) => {
        alarmTotal.value = res.count;
      });
    }

    /**
     * 初始化设备总数
     */
    function initEquipmentCount() {
      equipmentCountApi().then((res) => {
        onlineEquipmentCount.value = res.totalCount;
      });
    }

    onMounted(() => {
      alarmCount();
      initEquipmentCount();
    });

    return {
      alarmTotal,
      onlineEquipmentCount,
      alarmCount,
      initEquipmentCount,
    };
  },
});
</script>

<style lang="less" scoped>
.left-echarts-node {
  width: 100%;
  height: 250px;
  padding: 0 0 24px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.27) 0%, rgba(0, 0, 0, 0.01) 100%);
  backdrop-filter: blur(100px);
  .tip {
    position: relative;
    width: 100%;
    height: 44px;
    padding: 0 0 0 43.3px;
    background: url('@/assets/images/img-39.png') no-repeat;
    background-size: 100% 100%;
    line-height: 44px;
    font-size: 16px;
    color: #fff;
    span {
      position: relative;
    }
    .dv-decoration-2 {
      position: absolute;
      bottom: 0;
      left: 11px;
      width: 95%;
      height: 5px;
    }
  }
  .legend-list {
    margin: 20.66px 0 0;
    ul {
      display: grid;
      padding: 0 12px;
      margin: 0;
      grid-template-columns: repeat(2, 1fr);
      grid-gap: 30px 40px;
      li {
        width: 100%;
        color: #fff;
        &:first-child {
          .info {
            &::before {
              background: #1ef0d7;
            }
          }
        }
        &:nth-child(2) {
          .info {
            &::before {
              background: #3d67ff;
            }
          }
        }
        &:nth-child(3) {
          .info {
            &::before {
              background: #47bc79;
            }
          }
        }
        .info {
          position: relative;
          &::before {
            content: '';
            position: relative;
            top: -12px;
            display: block;
            width: 7px;
            height: 7px;
            margin: 10px 12px 0 0;
          }
          p {
            padding: 0;
            margin: 0;
            span {
              display: block;
              width: 100%;
              font-family: 'HarmonyOS Sans SC';
              &:first-child {
                font-size: 16px;
              }
              &:last-child {
                font-size: 12px;
              }
            }
          }
        }
        .ant-progress {
        }
      }
    }
  }
  .card {
    width: calc(100% - 48px);
    padding: 12px 24px;
    margin: 20px;
    background-color: #679c7a;
    border-radius: 10px;
    color: #fff;
    .title {
      font-size: 25px;
    }
    .value {
      font-size: 35px;
      font-family: Aldrich;
      text-align: right;
    }
  }
}
</style>
